package backend.majiong.yaku.yakuman;

import java.util.HashMap;
import java.util.Map;

import backend.MainGame;
import backend.majiong.Pai;
import backend.majiong.Player;
import backend.majiong.yaku.AbstractYaku;
import backend.majiong.yaku.HandCombo;
import backend.majiong.yaku.yaku.Tinitu;

public class Cyuurennpoutou extends AbstractYaku {

    @Override
    public boolean checkYaku(Player player, HandCombo combo, MainGame mainGame) {
        if (!combo.getIsMengQing()) {
            return false;
        }
        if (!new Tinitu().checkYaku(player, combo, mainGame)) {
            return false;
        }
        Map<Integer, Integer> countMap = new HashMap<Integer, Integer>();
        for (Pai pai : combo.getAllHandPai()) {
            Integer num = countMap.get(pai.getNum());
            if (num != null) {
                countMap.put(pai.getNum(), num + 1);
            }
            countMap.put(pai.getNum(), 1);
        }
        for (int i = 1; i < 10; i++) {
            if (i == 1 || i == 9) {
                if (countMap.get(i) < 3) {
                    return false;
                }
            } else {
                if (countMap.get(i) < 1) {
                    return false;
                }
            }

        }
        return false;
    }

    @Override
    public String getYakuName() {
        return "九莲宝灯";
    }

    @Override
    public Integer getYakuNum(boolean isMenQing) {
        return 13;
    }

}
